<!DOCTYPE html>
<html lang="en" class="app">
<head>
<meta charset="utf-8" />
<title>微信账号管理</title>
<meta name="description" content="app, web app, responsive, admin dashboard, admin, flat, flat ui, ui kit, off screen nav" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <link rel="stylesheet" href="${s.base}/js/layui/css/layui.css" media="all" />
  <link rel="stylesheet" href="${s.base}/css/base/base.css" media="all" />

</head>
<body class="childrenBody">
<form class="layui-form">
  <blockquote class="layui-elem-quote quoteBox">
    <form class="layui-form">
      <div class="layui-inline">
        <label class="layui-input-inline">微信Appid：</label>
        <div class="layui-input-inline">
          <input type="text" class="layui-input" id="appid" placeholder="请输入微信Appid" />
        </div>
        <a class="layui-btn search_btn" data-type="reload">搜索</a>
        <a class="layui-btn layui-btn-normal add_btn">添加</a>
      </div>

    </form>
  </blockquote>
  <table id="entityList" lay-filter="entityList"></table>

</form>
<script type="text/javascript" src="${s.base}/js/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['form','layer','laydate','table','laytpl'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table;

        //列表
        var tableIns = table.render({
            elem: '#entityList',
            url : '/wxAccount/JsonList',
            cellMinWidth : 95,
            page : true,
            height : "full-125",
            limit : 20,
            method:'post',
            limits : [10,15,20,25],
            id : "entityList",
            cols : [[
                {type: 'numbers', title: '序号'},
                {field: 'name', title: '应用名称',align:'center'},
                {field: 'appid', title: '微信appid',align:'center'},
                {field: 'appsecret', title: '微信appsecret',align:'center'},
                {field: 'templateId', title: '消息模板id',align:'center'},
                {title: '页面模板',align:"center", width:200,templet:function(d){
                    if(d.templateNum==null||d.templateNum==""){
                        return "默认模板";
                    }else{
                        return d.templateNum+"模板";
                    }
                }},
                {field: 'baseURL', title: '基础路径',align:'center'},
                {title: '访问地址',align:"center", width:200,templet:function(d){
                    return '<input type="text" value="'+d.baseURL+'/weiXin/oauth/1?wxId='+d.id+'" style="width: 90%;"/>';
                }},
                {title: '操作',align:"center", width:90,templet:function(d){
                    return '<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>';
                }}
            ]]
        });
        $(".add_btn").click(function(){
            addEntity('');
        })

        //搜索
        $(".search_btn").on("click",function(){
            table.reload("entityList",{
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where: {
                    appid:$("#appid").val()
                }
            })
        });

        //增加/编辑
        function addEntity(params){
            var title="编辑";
            if(params==null||params==""){
                title="添加"
            }
            var index = layui.layer.open({
                title :title,
                type : 2,
                content : "/wxAccount/SelectEntity"+params,
                success : function(layero, index){
                    var body = layui.layer.getChildFrame('body', index);
                    body.find(".closeLay").bind("click",function () {
                        layui.layer.close(index);
                    })
                    layui.layer.full(index);
                }
            });
        }

        //列表操作
        table.on('tool(entityList)', function(obj){
            var layEvent = obj.event,
                data = obj.data;
            if(layEvent === 'edit'){ //编辑
                addEntity("?id="+data.id);
            }
        });

    })
</script>
</body>
</html>
